<?php

namespace common\models\business;

use Yii;

/**
 * This is the model class for table "business_inspection".
 *
 * @property string $id
 * @property string $healthy
 * @property integer $business_person
 * @property integer $pigid
 * @property string $weight
 * @property string $height
 * @property string $length
 * @property string $width
 * @property string $pigpen
 * @property string $pigpen_desc
 * @property string $pigpen_photo
 * @property string $feed
 * @property string $feed_desc
 * @property string $feed_photo
 */
class BusinessInspection extends \yii\db\ActiveRecord
{

    //主要用于日志记录
    public $uselog = [
        'tabcomment' => '巡检',      //用于修改了什么的显示
        'mainfield' => 'id',      //主要的显示标题的字段
        'picturefield' => [],        //图片字段
        'timefield' => [],       //时间字段
        'unsetfiled' =>[],      //不需要记录的字段
    ];


    public static $healthys = [
        '正常，食欲旺盛，吃的快又多',
        '一般，食欲一般，吃的不多',
        '不正常，吃得少，无食欲',
        '极不正常，无食欲'
    ];

    public static $pigpens = [
        '干净，干燥，无粪便',
        '不干净，有少量粪便',
        '不干净，潮湿，有大量粪便'
    ];

    public static $feeds = [
        0 => '粗粮',
        1 => '细粮',
        2 => '粗细粮搭配',
        3 => '绿色植物',
        4 => '农作物',
    ];


    public static $situation = [
        0 => '良好',
        1 => '正常',
        2 => '一般',
        3 => '差',
    ];


    const STATUS_PASSED = 1;
    const STATUS_UNPASSED = -1;
    const STATUS_NOLOOK = 0;

    //删除进入回收站
    const ISDEL_DEL = -1;
    const ISDEL_NODEL = 0;

    public static $statues = [
        self::STATUS_PASSED => '审核通过',
        self::STATUS_UNPASSED => '审核未通过',
        self::STATUS_NOLOOK => '未审核'
    ];


    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'business_inspection';
    }


    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['business_personid', 'pigid', 'weight', 'length', 'width', 'pigpen','status'], 'required'],
            [['business_personid' ,'pigid','createtime','status','cleanpen','disinfection','is_del'], 'integer'],
            [['lat' ,'lng','weight','length', 'width','height'], 'number'],
            [['lat' ,'lng','weight','length', 'width','height','cleanpen','disinfection'], 'default','value'=>0],
            [['business_person','healthy','healthy_desc', 'pigpen', 'pigpen_desc', 'feed', 'feed_desc','situation','address'], 'string', 'max' => 255],
            [['activelevel','haircolor','foodintake','shit','temperature','breath','season'], 'string', 'max' => 100],            [['activelevel','haircolor','foodintake','shit','temperature','breath','season'], 'string', 'max' => 100],
            [['remark'], 'string', 'max' => 500],
            [['urine','pen_temperature'], 'string', 'max' => 30],
            [['pigpen_photo', 'pigphoto' ,'feed_photo'], 'image','extensions' => ['png', 'jpg', 'gif'], 'maxSize' => 1024*1024*1024,'on'=>'update,create'],
        ];
    }


    public function scenarios()
    {
        $scenarios = parent::scenarios();//本行必填，不写的话就会报如上错误
        $scenarios['create'] = ['pigpen_photo', 'pigphoto', 'feed_photo'];
        $scenarios['update'] = ['pigpen_photo', 'pigphoto', 'feed_photo'];

        return $scenarios;
    }


    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'healthy' => '健康状况',
            'person' => '巡检人',
            'pig' => '巡检仔猪编号',
            'pigid' => '巡检仔猪',
            'weight' => '体重(kg)',
            'height' => '身高(cm)',
            'length' => '身长(cm)',
            'width' => '身宽(cm)',
            'pigpen' => '猪舍情况',
            'pigpen_desc' => '猪舍情况简述',
            'pigpen_photo' => '猪舍照片',
            'feed' => '食料情况',
            'feed_desc' => '食料情况简介',
            'feed_photo' => '食料照片',
            'createtime' => '巡检时间',
            'business_personid' => '巡检人id',
            'business_person' => '巡检人',
            'situation' => '体测状态',
            'activelevel' => '精神',
            'haircolor' => '毛色',
            'season' => '季节',
            'foodintake' => '食量',
            'shit' => '大便情况',
            'breath' => '呼吸情况',
            'temperature' => '体温',
            'pigphoto' => '仔猪照片',
            'lat' => '巡检纬度',
            'lng' => '巡检精度',
            'address' => '巡检地址',
            'status' => '是否通过审核',
            'remark' => '审核备注'
        ];
    }


    /**
     * @return \yii\db\ActiveQuery
     * 获取巡检仔猪
     */
    public function getPig()
    {
        return $this->hasOne(BusinessPig::className(),['id'=>'pigid']);
    }

    /**
     * @return \yii\db\ActiveQuery
     * 巡检业务人员信息
     */
    public function getPerson()
    {
        return $this->hasOne(BusinessPerson::className(),['id'=>'business_personid']);
    }


}
